<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
    var editor;
	$(function(){
        parent.$.messager.progress('close');
		$("#submitbutton").click(function(){
			var cotent=editor.getContent();
			var imageurl=getimagurl(cotent);
			var title=$("#title").val();
			
			if(titile===""||cotent===""){
				alert("标题或内容不能为空@!@");
			}else{
				$.post("${pageContext.request.contextPath}/interactController/uploadcontent",{random:Math.random(),content:cotent,imageurl:imageurl,title:title},function(rs){
					var msg=eval("("+rs+")");
			
					alert(msg.msg);
                    editor.setContent("");
					$("#title").val("");
				});
			}
					
		});
		
		$("#cleartbutton").click(function(){

			$("#title").val("");
            editor.setContent("");
		});
	});
	
	function getimagurl(cotent){
		
		  var re=/(http(s)?\:\/\/)?(www\.)?(\w+\:\d+)?(\/\w+)+\.(swf|gif|jpg|bmp|jpeg|png)/gi;
		  var arr=cotent.match(re);

		 // for(var i=0;i<arr.length;i++){
		//   document.getElementById("txt").value+=arr[i]+"\n";
		//  }
		
		if(arr!=null&&arr!=undefined){
			if(arr.length>0){
				return arr[0];
			}
		}
		
		return "";
	}
</script>

	<script id="container" name="content" type="text/plain">
    	${interact.content}
	</script>
	<script type="text/javascript">
        if(editor==null||editor==undefined){
            editor = UE.getEditor('container');
        }else{
            editor.destroy();
            editor = UE.getEditor('container');
        }

	</script>
	<div>标题：</div>
	<div>
		<textarea rows="3" cols="30" id="title">${interact.title}</textarea>
	</div>
	<input type="button" id="submitbutton" value="发布"><input type="button" id="cleartbutton" value="清空">
